package org.example.service.impl;

import org.example.mapper.EmpMapper;
import org.example.mapper.StudentMapper;
import org.example.pojo.ClazzOption;
import org.example.pojo.JobOption;
import org.example.service.ReportService;
import org.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.text.html.Option;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    /*
    * 统计员工职位人数
    * */
    @Override
    public JobOption getEmpJobData() {
        // 1.调用Mapper接口，获取统计的数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        // 2.组装结果并返回
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();

        return new JobOption(jobList, dataList);
    }

    /*
    * 统计员工性别
    * */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        // 调用Mapper层
        List<Map<String, Object>> list = empMapper.countEmpGenderData();
        return list;
    }

    /*
    * 统计学生学历人数
    * */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        List<Map<String, Object>> list = studentMapper.countStudentDegreeData();
        return list;
    }

    /*
    * 班级人数统计
    * */
    @Override
    public ClazzOption getStudentCountData() {
        // 1.调用Mapper接口
        List<Map<String, Object>> list = studentMapper.countStudentCountData();

        // 2.将结果封装
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("name")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("value")).toList();

        return new ClazzOption(clazzList, dataList);
    }
}
